<?php
/**
 * 小程序配置
 */
namespace app\Admin\controller;

use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;

class Applet extends Basic
{
    // 小程序设置
    public function index(){
        $info = Db::name('wechat_applet')->where('id',1)->find();
        $info['updatetime'] = date('Y-m-d H:i:s', $info['updatetime']);
        if (Request::instance()->isPost()){
            $id     = input('post.id/d');
            $title  = input('post.title');
            $appid  = input('post.appid');
            $secret = input('post.secret');
            if(!$appid || $secret){
                $this->error('小程序参数不能为空！',url('Index/pwd'));
            }
            $data = array(
                'id'         => $id,
                'title'      => trim($title),
                'appid'      => trim($appid),
                'secret'     => trim($secret),
                'updatetime' => time(),
            );
            $result = DB::name('wechat_applet')->update($data);
            if($result) {
                $this->success('更新成功！',url('Index/index'));
            }else{
                $this->error('更新失败！',url('Index/index'));
            }
            return;
        }
        // print_r($info);die();
        $this->assign('info', $info);
        $this->assign('title', '小程序设置');
        return $this->fetch();
    }

}